// Written by Craig'n'Dave
using System;
// Circular queue using an array
namespace ConsoleApp1
{
    class Program
    {
        public class Queue
        {
            private static int max = 10;
            private static string[] items = new string[max];

            private static int front_pointer = -1;
            private static int back_pointer = -1;

            public bool enqueue(string item)
            {
                // Check queue overflow
                if ((back_pointer + 1) % max != front_pointer)
                {
                    back_pointer = (back_pointer + 1) % max;
                    // Enqueue the item
                    items[back_pointer] = item;
                    // Set first item if queue was empty
                    if (front_pointer == -1)
                    {
                        front_pointer = 0;
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }

            public string dequeue()
            {
                // Check queue underflow
                if (front_pointer != -1)
                {
                    // Dequeue the item
                    string item = items[front_pointer];
                    // If the queue is not empty change the front pointer
                    if (front_pointer != back_pointer)
                    {
                        front_pointer = (front_pointer + 1) % max;
                    }
                    else
                    {
                        // When the last item is dequeued reset the pointers
                        front_pointer = -1;
                        back_pointer = -1;
                    }
                    return item;
                }
                else
                {
                    return null;
                }
            }

            public string peek()
            {
                // Check queue underflow
                if (front_pointer != -1)
                {
                    // Peek the item
                    return items[front_pointer];
                }
                else
                {
                    return null;
                }
            }
        }

        // Main program starts here
        static void Main(string[] args)
        {
            string[] items = new string[] { "Florida", "Georgia", "Delaware", "Alabama", "California" };
            Queue q = new Queue();
            // Add items to the queue
            for (int index = 0; index < items.Length; index++)
            {
                q.enqueue(items[index]);
            }
            // Remove items from the queue
            Console.WriteLine(q.dequeue());
            // Output the next item in the queue
            Console.WriteLine(q.peek());
        }
    }
}
